package cfengMiddleware.server.rabbitmq.producer;

import cfengMiddleware.server.rabbitmq.entity.MessageEntity;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RQueue;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Component;

/**
 * @author Cfeng
 * @date 2022/9/23
 */

@Component
@RequiredArgsConstructor
@Slf4j
public class RedissonQueuePublisher {

    private final RedissonClient redissonClient;

    public void sendMsg(MessageEntity messageEntity) {
        //定义该队列组件的名称
        final String queueName = "redissonBasicQueue";

        //声明组件
        RQueue<MessageEntity> rQueue = redissonClient.getQueue(queueName);
        //使用组件向队列组件中发送消息
        try {
            rQueue.add(messageEntity);
            log.info("Redisson消息发送成功，RQueue: {}",messageEntity);
        } catch (Exception e) {
            log.error("redisson消息发送失败");
        }
    }
}
